package com.agileboot.domain.system.dict.model;


import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.system.dict.db.SysDictTypeEntity;
import com.agileboot.domain.system.dict.db.SysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DictTypeModelFactory{

    private final SysDictTypeService dictTypeService;

    public DictTypeModel loadById(Long dictId){
        SysDictTypeEntity byId =dictTypeService.getById(dictId);
        if (byId == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, dictId, "字典管理");
        }

        return new DictTypeModel(byId,dictTypeService);
    }

    public DictTypeModel create() {
        return new DictTypeModel(dictTypeService);
    }
}
